//
//  CustomSearchHeadView.m
//  JJHW_coreData
//
//  Created by lizhenqiang on 16/4/16.
//  Copyright © 2016年 HFKJ_LZQ. All rights reserved.
//

#import "CustomSearchHeadView.h"
/*
 @property(strong, nonatomic)UIButton *newsBtn;
 @property(strong, nonatomic)UIButton *questionBtn;
 @property(strong, nonatomic)UIButton *dibiaoBtn;
 
 @property(strong, nonatomic)UIImageView *xianImageView;
 
 */

@implementation CustomSearchHeadView
@synthesize contentType = _contentType;
-(void)awakeFromNib
{
    
    
}

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _mywidth = frame.size.width;
        _myheight = frame.size.height;
        CGFloat startWidth = 20;
        CGFloat startHeight = 15;
        CGFloat btnHeight = 36;
        CGFloat btnWidth = kScaleFrom_iphone6_Desgin(90);
        CGFloat jg = (DeviceWidth-btnWidth*3-40)/2;
        _newsBtn = [[UIButton alloc] initWithFrame:CGRectMake(startWidth, startHeight,btnWidth, btnHeight)];
        _questionBtn = [[UIButton alloc] initWithFrame:CGRectMake(_newsBtn.frame.origin.x+btnWidth+jg, startHeight, btnWidth, btnHeight)];
        _dibiaoBtn = [[UIButton alloc] initWithFrame:CGRectMake(_questionBtn.frame.origin.x+btnWidth+jg, startHeight, btnWidth, btnHeight)];
        UIImage *normalImage = [UIColor imageFromColor:CGRectMake(0, 0, btnWidth, btnHeight) andColor:TabBarBjNormalColor];
        UIImage *selectedImage = [UIColor imageFromColor:CGRectMake(0, 0, btnWidth, btnHeight) andColor:TabBarBjSelectColor];
        [_newsBtn setTitle:@"资讯" forState:UIControlStateNormal];
        [_newsBtn setBackgroundImage:normalImage forState:UIControlStateNormal];
        [_newsBtn setTitleColor:kDefaultWhiteColor forState:UIControlStateNormal];
        _newsBtn.titleLabel.font = themeFont15;
        [_newsBtn setBackgroundImage:selectedImage forState:UIControlStateSelected];
        
        [_questionBtn setTitle:@"问答" forState:UIControlStateNormal];
        [_questionBtn setTitleColor:kDefaultWhiteColor forState:UIControlStateNormal];
        _questionBtn.titleLabel.font = themeFont15;
        [_questionBtn setBackgroundImage:normalImage forState:UIControlStateNormal];
        [_questionBtn setBackgroundImage:selectedImage forState:UIControlStateSelected];
        
        [_dibiaoBtn setTitle:@"地标" forState:UIControlStateNormal];
        [_dibiaoBtn setTitleColor:kDefaultWhiteColor forState:UIControlStateNormal];
        _dibiaoBtn.titleLabel.font = themeFont15;
        [_dibiaoBtn setBackgroundImage:normalImage forState:UIControlStateNormal];
        [_dibiaoBtn setBackgroundImage:selectedImage forState:UIControlStateSelected];
        
        _newsBtn.layer.cornerRadius = 18.0f;
        _newsBtn.layer.masksToBounds = YES;
        _questionBtn.layer.cornerRadius = 18.0f;
        _questionBtn.layer.masksToBounds = YES;
        _dibiaoBtn.layer.cornerRadius = 18.0f;
        _dibiaoBtn.layer.masksToBounds = YES;
       
        _newsBtn.tag = 100;
        _questionBtn.tag = 101;
        _dibiaoBtn.tag = 102;
        [_newsBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
        [_questionBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
        [_dibiaoBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:_newsBtn];
        [self addSubview:_questionBtn];
        [self addSubview:_dibiaoBtn];
        
        _xianImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, _myheight, DeviceWidth, 1)];
        _xianImageView.image = [UIImage imageNamed:@"labelxian"];
        [self addSubview:_xianImageView];
//        [_newsBtn mas_makeConstraints:^(MASConstraintMaker *maker){
//            maker.top.equalTo(self.mas_top).offset(startHeight);
//            maker.width.equalTo(_questionBtn.mas_width).equalTo(_dibiaoBtn.mas_width);
////            maker.leftMargin.equalTo(self.mas_left).offset(20);
//            maker.left.equalTo(self.mas_left).offset(20);
//            maker.right.equalTo(_questionBtn.mas_left).offset(20);
//            
//        }];
//        [_questionBtn mas_makeConstraints:^(MASConstraintMaker *maker){
//            maker.top.equalTo(self.mas_top).offset(startHeight);
//            
//            maker.width.equalTo(_newsBtn.mas_width).equalTo(_dibiaoBtn.mas_width);
//            maker.left.equalTo(_newsBtn.mas_right).offset(20);
//            maker.right.equalTo(_dibiaoBtn.mas_left).offset(20);
//
//        }];
//        [_dibiaoBtn mas_makeConstraints:^(MASConstraintMaker *maker){
//            maker.top.equalTo(self.mas_top).offset(startHeight);
//            maker.width.equalTo(_newsBtn.mas_width).equalTo(_questionBtn.mas_width);
//            maker.left.equalTo(_questionBtn.mas_right).offset(20);
//            maker.right.equalTo(self.mas_right).offset(20);
//            
//        }];
        
    }
    return self;
}
-(void)setContentType:(KcontentType)contentType
{
    _contentType = contentType;
    [self setViewData];
}
-(KcontentType)contentType
{
    return _contentType;
}

-(void)setViewData
{
    switch (_contentType) {
        case contentTypeNews: {
            _selectedBtn = _newsBtn;
            _selectedBtn.selected = YES;
            break;
        }
        case contentTypeQuestion: {
            _selectedBtn = _questionBtn;
            _selectedBtn.selected = YES;
            break;
        }
        case contentTypeDibiao: {
            _selectedBtn = _dibiaoBtn;
            _selectedBtn.selected = YES;
            break;
        }
    }
}
-(void)btnClicked:(UIButton *)sender
{
    if (!sender.selected) {
        _selectedBtn.selected = NO;
        _selectedBtn = sender;
        _selectedBtn.selected = YES;
        switch (sender.tag) {
            case 100:
            {
                _contentType = contentTypeNews;
            }
                break;
            case 101:
            {
                _contentType = contentTypeQuestion;
            }
                break;
            case 102:
            {
                _contentType = contentTypeDibiao;
            }
                break;
                
            default:
                break;
        }
        
        if (_block) {
            _block(_contentType);
        }
    }
    
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
